import $ from 'jquery';
let photoCommon = function() {
  return {
    /* 重置瀑布流数据源*/
    countFullCols(picList) {
      let windowWidth = document.body.clientWidth;
      let colspan;
      if (windowWidth > 1920) {
        colspan = 3;
      } else if (windowWidth <= 1920 && windowWidth > 1600) {
        colspan = 4;
      } else if (windowWidth <= 1600 && windowWidth > 1200) {
        colspan = 6;
      } else if (windowWidth < 1200 && windowWidth >= 960) {
        colspan = 8;
      } else {
        colspan = 12;
      }

      let cols = 24 / colspan;
      let nPicList = [];
      for (let i = 0; i < cols; i++) {
        nPicList.push([]);
      }
      /* picList.forEach(function(v, i) {
        nPicList[i % cols].push(v);
      }) */
      return nPicList;
    },
    /* 图片放大器,点击遮罩空白处关闭*/
    imgMaskClose() {
      $(document).on("click", ".el-image-viewer__wrapper", function(e) {
        if ($(e.target).closest(".el-image-viewer__img").length < 1 && $(e.target).closest(
            ".el-image-viewer__btn").length < 1) {
          $(".el-image-viewer__btn.el-image-viewer__close").click();
        }
      })
    },
    /* 图片加载完成后,再加载下一张图片*/
    photoLoadEvt(newPicList, clonePiclist,totalCont) {
      if (clonePiclist.length > 0) {
        let height = document.getElementById("el-col-img-0").offsetHeight;
        let minHeightInd = 0;
        for (let i = 0, len = newPicList.length; i < len; i++) {
          let sHeight = document.getElementById("el-col-img-" + i).offsetHeight
          if (sHeight < height) {
            height = sHeight;
            minHeightInd = i; //获取高度最小的列
          }
        }
        newPicList[minHeightInd].push(clonePiclist[0]) //往最小高度列里加一条数据
        clonePiclist.splice(0, 1) //加完直接移除一条，方便下次添加
      };
    },
  };
}();
export default photoCommon;
